<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<!-- <script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script> -->
<script src="<?php echo URL::base() ?>media/laydate/laydate.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.core.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.widget.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.position.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.autocomplete.min.js"></script>

<div class="container-fluid">
    <form class="form-horizontal" method="GET" action='<?php echo URL::site() ?>shortage/index'>
        <div class="control-group">
            <label class="control-label">SKU:</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="sku" id="sku" value="<?php echo $_GET['sku'];?>" >
            </div>
        </div>
        <div class="control-group" id="group">
            <span class="control-label">供应商:</span>
            <div class="controls">
                <!--<input type="text" class="input-mini" name="supplier_id" id="supplier_id" value="<?php echo $get['supplier_id'];?>" readonly="readonly"/>-->
               <input type="text" class="input-xlarge" name="supplier_name" id="supplier_name" value="<?php echo $get['supplier_name'];?>" placeholder="请输入供应商" autocomplete="off"/>
               <!--<a class="btn" href="javascript:clear();">重选</a>-->
            </div>
    	</div> 
        <div class="control-group">
            <label class="control-label">仓库:</label>
            <div class="controls">
                <select name="warehouseid" id="warehouseid" class="input-xlarge">
                <option value="">请选择</option>
                <?php 
                $store_list = Kohana::$config->load('vmi_warehouse')->as_array();
                if (is_array($store_list) && !empty($store_list)) {
                    foreach ($store_list as $storeId => $store) {
                        ?>
                        <option value="<?php echo $storeId; ?>" <?php if (isset($get['warehouseid']) && $get['warehouseid'] == $storeId) {
                            echo "selected='selected'";
                        } ?>><?php echo $store; ?></option>
                    <?php }
                } ?>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">主体:</label>
            <div class="controls">
                <select name="enterprise_dominant" id="enterprise_dominant" class="input-xlarge">
                    <option value="">全部</option>
                <?php $body_arr = Kohana::$config->load('enterprise_dominant')->as_array();?>
                <?php foreach ($body_arr as $k=>$v){?>
                    <option value="<?php echo $k;?>" 
                        <?php if(isset($get['enterprise_dominant']) && $k==$get['enterprise_dominant']) 
                            echo 'selected';?>>
                        <?php echo $v;?>
                    </option>
                <?php }?>
                </select>
            </div>
        </div>
        <!--
        <div class="control-group">
            <label class="control-label">起止时间从:</label>
            <div class="controls">
                <input  class="input-medium datepicker" type="text"
                        value="<?php if (isset($get['date_from'])) {
                            echo $get['date_from'];
                        } ?>" name='date_from' id="date_from" />
                到 <input  class="input-medium datepicker" type="text"
                          value="<?php if (isset($get['date_to'])) {
                              echo $get['date_to'];
                          } ?>" name='date_to' id="date_to" />
            </div>
        </div>
        -->
        <div class="control-group">
            <div class="controls">
                <input class="btn btn-info" type="submit" value="查询"/>
                <input class="btn" type="submit" name="export" id="downbtn" value="导出"/>
            </div>
        </div>
    </form>
    <table class="table table-hover ">
        <thead>
        <tr>
            <th>SKU</th>
            <th>仓库</th>
            <th>供应商</th>
            <th>主体</th>
            <th>中文名称</th>
            <th>规格</th>
            <th>储位</th>
            <th>期初</th>
            <th>期入</th>
            <th>期出</th>
            <th>期末结存</th>
        </tr>
        </thead>
        <?php 
        $companies[0] = '<span style="color:gray">无主体</span>';
        foreach ($data as $k=>$v){
        ?>
        <tr>
            <td><?php echo $v['sku'];?></td>
            <td><?php echo $warehouses[$v['warehouseid']]['name'];?></td>
            <td><?php echo $v['supplier_name'];?></td>
            <td><?php echo isset($companies[$v['enterprise_dominant']]) ? $companies[$v['enterprise_dominant']] : '';?></td>
            <td><?php echo $v['productname'];?></td>
            <td><?php echo $v['nuit'];?></td>
            <td><?php echo $v['position'];?></td>
            <td><?php echo $v['begin_qty'] . '|' . sprintf('%.2f',$v['begin_amount']);?></td>
            <td><?php echo $v['in_qty'] . '|' . sprintf('%.2f',$v['in_amount']);?></td>
            <td><?php echo $v['out_qty'] . '|' . sprintf('%.2f',$v['out_amount']);?></td>
            <td><?php echo $v['end_qty'] . '|' . sprintf('%.2f',$v['end_amount']);?></td>
        </tr>
        <?php }?>
    </table>
    <?php echo $pagination;?>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        laydate.render({
            elem: '#date_from'
        });
        laydate.render({
            elem: '#date_to'
        });
        
        /**
         * 查询供应商自动提示补全
         */
        $("#supplier_name").autocomplete({
            autoFocus: true,
            minLength: 0,
            autoFill: true,
            source: '<?php echo URL::base(true)?>purchase/get_supplier',
            select: function (event, ui) {
                //从建议列表中选中之后触发的事件
                $("#supplier_name").val(ui.item.name);
                // $("#supplier_id").val(ui.item.id);
                // $("#supplier_name").attr("readonly", "readonly");
                return false;
            }
        });
    });
    function clear(e){
        var e = e || window.event;
        $("#supplier_id").val('');
        $("#supplier_name").val('');
        $("#supplier_name").attr("readonly", false);
        if(typeof(e) == 'undefined'){
			return ;
        }else{
        	e.preventDefault && e.preventDefault();
        }
    }
</script>